package com.haircut.utils;

import cn.hutool.core.util.StrUtil;
import com.haircut.sys.vo.permission.PermissionVo;
import com.modular.enums.DataScope;

import java.util.ArrayList;
import java.util.List;
import java.util.Objects;

public class PermissionUtils {
    public static List<String> coverPermission(PermissionVo permissionVo){
        List<String> permison = new ArrayList<>();
        // 如果是只查询个人
        if(Objects.equals(permissionVo.getDataScope(), DataScope.SELF.getCode())){
            permison.add(StrUtil.format( "and EXISTS ( select 1 from t_sys_user where id = {} and id ='{}')",permissionVo.getParentUserId(),permissionVo.getUserId()));
        }else if(Objects.equals(permissionVo.getDataScope(),DataScope.DEPT.getCode())){
            permison.add(StrUtil.format( "and EXISTS ( select 1 from t_sys_dept where id = {} and id ='{}')",permissionVo.getParentDeptId(),permissionVo.getDeptId()));
        }else if(Objects.equals(permissionVo.getDataScope(),DataScope.DEPT_LEVL.getCode())){
            permison.add(StrUtil.format( "and EXISTS ( select 1 from t_sys_dept where id = {} and hierarchy like '{}%')",permissionVo.getParentDeptId(),permissionVo.getHierarchy()));
        }

        return permison;
    }
}
